<include file="public@storage"/>
</head>
<body>
<div class="container body-content" style="margin-top:20px;width: 100%">
    <div class="panel panel-info" style="margin-bottom: 0.5rem">
        <div class="panel-heading"><span id="storageName">{$storageInfo[0]['name']}</span>站位管理</div>
        <input type="hidden" id="storageUuid" value="{$storageInfo[0]['uuid']}">
        <input type="hidden" id="shelfUuid" value="{$shelfUuid}">
        <div class="panel-body">
            <div class="row">
                <div class="col-sm-12">
                    <div id="toolbar" class="btn-group">
                        <select id="selectStorage" class="btn btn-info" style="margin-left: 5px; width: 10rem"
                                onchange="changeStorage()">
                            <option>请选择仓库</option>
                            <volist id="uuid" name="storageInfo" id="value">
                                <option value="{$value['uuid']}">{$value['name']}</option>
                            </volist>
                        </select>

                    </div>
                    <table id="table"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script src="__STATIC__/storage/js/common/selectStorage.js"></script>
<script>
    var storageUuid = $("#storageUuid").val();
    var shelfUuid = $("#shelfUuid").val();
    var status = $("#selectStatus").val();
    $(function () {
        if (shelfUuid === '') {
            $("#selectStorage").show();
        } else {
            $("#selectStorage").hide();
        }
        init();
    });

    function init() {
        var url = "{:url('storage/Seat/getSeat')}?storageUuid=" + storageUuid + '&shelfUuid=' + shelfUuid + '&status=' + status;
        var columns = [
            {
                title: '序号',
                width: 50,
                align: "center",
                valign: 'middle',
                formatter: function (value, row, index) {
                    return index + 1;
                }
            },
            {
                title: 'uuid',
                field: 'uuid',
                visible: false
            },
            {
                title: '站位码',
                field: 'seat_code',
                align: "center",
                filter: {
                    type: 'input'
                }
            },
            {
                title: '设备码',
                field: 'seat_id',
                align: "center",
                filter: {
                    type: 'input'
                }
            },
            {
                title: '所属仓库',
                field: 'name',
                align: "center",
                filter: {
                    type: 'input'
                }
            },
            {
                title: '状态',
                field: 'status',
                align: "center",
                width:300,
                filter: {
                    type: 'select',
                    data: [{id: '', text: '所有'},{id: 0, text: '正常'},{id: 1, text: '异常'}]
                },
                formatter: function (value) {
                    if (value === 0) {
                        return '正常';
                    } else {
                        return '<span style="color:red;font-weight: bolder">' + '异常' + '</span>';
                    }
                }
            },
            {
                title: '操作',
                field: 'status',
                align: "center",
                valign: 'middle',
                width:300,
                formatter: function (value, row) {
                    var html = '<a onclick="changeStatus(this)" href="javascript:;"  data-seat="' + row.seat_code + '" data-uuid="' + row.uuid + '" >修改状态</a>';
                    return html;
                }
            }
        ];
        initTable(url, columns, 'server',false);
        setColumn();
    }

    function setColumn() {
        if (storageUuid === '') {
            $('#table').bootstrapTable('showColumn', 'name');
        } else {
            $('#table').bootstrapTable('hideColumn', 'name');
        }
    }
    add = function() {
        window.open('/storage/Shelf/add&storageUuid=' + storageUuid, '_self');
    };

    $('#selectStorage').change(function () {
        storageUuid = $('#selectStorage').val();
    });

    changeStatus = function(that) {
        var status = ['损坏','正常'];
        var seatCode = $(that).data('seat');
        var uuid = $(that).data('uuid');
        var row = $('#table').bootstrapTable('getRowByUniqueId', uuid);
        var param = {
            uuid: row['uuid'],
            status: row['status']
        };
        reviseTable('是否将' + seatCode+'标记为'+status[row['status']], "{:url('/storage/Seat/changeStatus')}", param);
    };

    selectStatus = function() {
        status = $('#selectStatus').val();
        setTimeout(function () {
            $('#table').bootstrapTable('destroy');
            init();
        }, 500);
    }

</script>
</html>